package com.itheima.controller;

import com.itheima.dto.MenuDTO;
import com.itheima.result.R;
import com.itheima.service.SysMenuService;
import com.itheima.vo.MenuChildrenVO;
import com.itheima.vo.MenuVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: kafka
 * @package: com.itheima.controller
 * @className: SysMenuController
 * @author: Eric
 * @description: TODO
 * @date: 2023/9/21 14:22
 * @version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/sys_menu")
@AllArgsConstructor
public class SysMenuController {
    private final SysMenuService sysMenuService;

    /**
     * 获取所有菜单数据
     *
     * @return {@link R}
     */
    @GetMapping("/allData")
    public R<List<MenuChildrenVO>> getAllMenusData(){
        List<MenuChildrenVO> menuChildrenVO = sysMenuService.getAllMenusData();
        return R.success(menuChildrenVO);
    }

    /**
     * 添加菜单
     *
     * @param menuDTO 菜单d到
     * @return {@link R}<{@link ?}>
     */
    @PostMapping("/add")
    public R<?> addMenu(@RequestBody MenuDTO menuDTO){
        sysMenuService.addMenu(menuDTO);
        return R.success();
    }

    /**
     * 删除菜单
     *
     * @param id id
     * @return {@link R}
     */
    @GetMapping("/del")
    public R<?> deleteMenu(Integer id){
        sysMenuService.deleteMenu(id);
        return R.success();
    }

    /**
     * 菜单信息
     *
     * @param id id
     * @return {@link R}<{@link MenuVO}>
     */
    @GetMapping("/rowInfo")
    public R<MenuVO> menuInfo(Integer id){
        MenuVO menuVO = sysMenuService.getMenuData(id);
        return R.success(menuVO);
    }

    /**
     * 更新菜单
     *
     * @param menuDTO 菜单d到
     * @return {@link R}<{@link ?}>
     */
    @PostMapping("/update")
    public R<?> updateMenu(@RequestBody MenuDTO menuDTO){
        sysMenuService.updateMenu(menuDTO);
        return R.success();
    }
}
